package com.akl.test.websocket;

import java.net.*;
import java.io.*;

/**
 * 客户端
 * 负责接收数据
 */
public class SocketClient {
    //    private static final String HOST = "127.0.0.1";
    private static final String HOST = "139.224.18.228";
    //    private static final int PORT = 5000;
    private static final int PORT = 4000;

    private static void test() {
        Socket socket = null;
        DataInputStream dis = null;
        InputStream is = null;
        OutputStream os = null;
        PrintWriter pw = null;
        try {

            socket = new Socket(HOST, PORT);
            os = socket.getOutputStream();
            pw = new PrintWriter(os);
            String registerInfo = "$$0,G8,T00000001,00000000001,50##"; //注册包

            for (int i = 0; i < 10; i++) {
                pw.write(registerInfo);
                pw.flush();
            }

            is = socket.getInputStream();
            dis = new DataInputStream(is);
            while (dis != null) {
                System.out.println("receive_msg:" + dis.readUTF());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {

        test();
    }
}